<template>
	<view class="parent-view">
		<text class="hi-text">Hi，欢迎来到拾亲~</text>
		<input class="input" placeholder="请输入拾亲号" @input="accountInput"/>
		<input class="input" placeholder="请输入密码" style="margin-top: 30rpx;" @input="passwordInput" password="true"/>
		<text class="login-btn" @click="login">登录</text>
	</view>
</template>

<script>
	import request from '../index/request.js';
	export default {
		data() {
			return {
				account:"",
				password:"",
			}
		},
		methods: {
			onLoad: function(options) {
				this.appUtil.saveAppInviteId(options)
			},
			onShow:function(){
				this.share.url='/pages/tabBar/home/index?appInviteId='+this.appUtil.getAppInviteId()
				this.share.shareType=1
			},
			accountInput:function(event){
				this.account=event.detail.value
			},
			passwordInput:function(event){
				this.password=event.detail.value
			},
			login:function(){
				if(!this.account){
					uni.showToast({
						icon:"none",
						title:"请输入拾亲号"
					})
					return
				}
				if(!this.password){
					uni.showToast({
						icon:"none",
						title:"请输入密码"
					})
					return
				}
				var that = this
				uni.showLoading()
				console.log("0000000000")
				request.post("api/user/login", {
					account: this.account,
					password: this.password
				}).then(data => {
					console.log("11111111")
					console.log(JSON.stringify(data))
					uni.setStorageSync("shiqin-user",data)
					uni.setStorageSync("shiqin-user-xing",data.nickname)
					uni.setStorageSync("shiqin-user-ming",data.nickcname)
					uni.setStorageSync("shiqin-user-sex",data.gender)
					if(data.nickname){
						uni.$emit('refrashHomeData')
						uni.$emit('refrashMineData')
						uni.reLaunch({
							url:"../tabBar/home/index"
						})
					}
				})
			},
			
		}
	}
</script>

<style>
	@import "index.css";
</style>
